# -*- coding:utf-8 -*-
from __future__ import absolute_import
import os
from django.utils import timezone

import django
from celery import Celery
from django.conf import settings
import logging

# 设置celery的环境变量和django-celery的工作目录
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'autotest.settings')
django.setup()
# 实例化celery应用，传入服务器名称
app = Celery('autotest')
# 加载celery配置
app.config_from_object('django.conf:settings')
# 如果在项目中，创建了task.py,那么celery就会沿着app去查找task.py来生成任务
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)

# 解决时区问题,定时任务启动就循环输出
app.now = timezone.now

logger = logging.getLogger('autotest')


@app.task(bind=True)
def debug_task(self):
    logger.debug("Request: {0!r}".format(self.request))
